// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import store from '@/vuex/store'   //全局状态管理  vuex
import router from './router'      //全局路由管理， route
import * as API from '@/api/common/index.js'
import { get, post,patch,del } from '@/api/common/common.js'

import { Loading } from 'element-ui';
// 引入elementui


import ElementUI from 'element-ui'
Vue.config.productionTip = false
Vue.use(ElementUI)



//四种请求封装封装ok后，写入原型链上面
Vue.prototype.$get = get
Vue.prototype.$post = post
Vue.prototype.$patch = patch
Vue.prototype.$del = del


/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})


//------------------------------------------------封装一个密码加密程序md4加密------------------------------------------------
String.prototype.md4 = function () {
  var v = "";
  var p = this.length;

  for (var i = 0; i < this.length; i++) {
      v += "-" + (this.charCodeAt(i) - p).toString(16);
  };
  return p.toString() + v;
};


//------------------------------------------------取消按钮------------------------------------------------

Vue.prototype.$canCleFn=function(){     
    router.go(-1)
}


//------------------------------------------------将时间戳改成日期格式------------------------------------------------
Vue.prototype.ChangeDateFormat = function (longtime, hasDate) {
  var time = new Date(longtime)
  var y = time.getFullYear()
  var m = time.getMonth() + 1
  var d = time.getDate()
  var returnResult = y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d)
  if (hasDate) {
    var h = time.getHours()
    var mm = time.getMinutes()
    var s = time.getSeconds()
    returnResult += ' ' + (h < 10 ? '0' + h : h) + ':' + (mm < 10 ? '0' + mm : mm) + ':' + (s < 10 ? '0' + s : s)
  }
  return returnResult
}

//------------------------------------------------下拉框获取设备类型值------------------------------------------------

Vue.prototype.$getDeviceType=async function(type,insOne){   //1城市运营   2设备管理  3品牌
             let res=await API.GET("/v1/flash/configs",{type:type})
             if(!insOne) res.Data.records.unshift({id: null,name: "全部"})
             return res.Data.records
}

//------------------------------------------------下拉框获取区域数据------------------------------------------------

Vue.prototype.$getSelect=async function(insOne){   
  let res=await API.GET("/v1/flash/storeAreas",{})
  if(!insOne) res.Data.records.unshift({id: null,name: "全部"})
  return res.Data.records
}


Vue.prototype.$RootOptions=async function(insOne){   //设备型号
  let res=await API.GET("/v1/flash/equipment/category",{})
  if(!insOne) res.Data.records.unshift({id: null,name: "全部"})
  return res.Data.records
}

Vue.prototype.$getservicename=async function(insOne){   //服务项目
  let res=await API.GET("/v1/flash/services",{})
  if(!insOne) res.Data.records.unshift({id: null,name: "全部"})
  return res.Data.records
}




//------------------------------------------------全局数据类型------------------------------------------------
Vue.prototype.$warehouse=(isOne)=>{         //仓库
  let house=  [    
    {id:1,name:"成品库"},
    {id:2,name:"运营库"},
    {id:3,name:"维修库"},
    {id:4,name:"报损库"},
  ]
  if(!isOne) house.unshift({id:null,name:"全部"},)
  return house
}
Vue.prototype.$currentStatus=(isOne)=>{         //设备状态
  let Status=  [    
    {id:1,name:"空闲中"},
    {id:2,name:"运行中"},
    {id:3,name:"故障中"},
    {id:4,name:"维修中"},
  ]
  if(!isOne) Status.unshift({id:null,name:"全部"},)
  return Status
}
Vue.prototype.$orderStatus=(isOne)=>{         //支付订单状态
  let Status=  [    
    {id:0,name:"进行中"},
    {id:1,name:"完成"},
    {id:2,name:"用户取消"},
    {id:3,name:"超时取消"},
    {id:4,name:"自动取消"},
    {id:5,name:"结束"},
    {id:6,name:"售后中"},
    {id:7,name:"售后完成"},
    {id:8,name:"待付款"},
    {id:9,name:"待启动"},
  ]
  if(!isOne) Status.unshift({id:null,name:"全部"})
  return Status
}
// isbinding 0  就是库存管理的  1  就是绑定了终端